#define _CRT_SECURE_NO_WARNINGS 1
#include<vector>
#include<iostream>
using namespace std;
class Solution1 {
public:
    vector<int> sortedSquares(vector<int>& nums) {
        int left = 0;
        int right = nums.size() - 1;
        vector<int> ret;
        ret.resize(nums.size());
        int leftnum = 0;
        int rightnum = 0;
        int sz = nums.size() - 1;
        while (sz)
        {
            leftnum = nums[left] * nums[left];
            rightnum = nums[right] * nums[right];
            if (rightnum > leftnum)
            {
                ret[sz] = rightnum;
                right--;
            }
            else
            {
                ret[sz] = leftnum;
                left++;
            }
            sz--;
        }
        return ret;
    }
};
class Solution2 {
public:
    void reserve(int left, int right, vector<int>nums)
    {
        while (left <= right)
        {
            nums[left] ^= nums[right];
            nums[right] ^= nums[left];
            nums[left] ^= nums[right];
            left++;
            right--;
        }
    }
    void rotate(vector<int>& nums, int k) {
        k %= nums.size();
        reserve(0, nums.size() - k - 1, nums);
        reserve(nums.size() - k, nums.size() - 1, nums);
        reserve(0, nums.size(), nums);
    }
};
class Solution {
public:
    void moveZeroes(vector<int>& nums) {
        for (int i = 0; i < nums.size() - 1;)
        {
            if (!nums[i])
            {
                for (int j = i; j < nums.size() - 2; j++)
                {
                    nums[j] = nums[j + 1];
                }
                nums[nums.size() - 1] = 0;
            }
            else
            {
                i++;
            }
        }
    }
};
int main()
{
    vector<int> arr = { 0,1,0,3,12 };
    Solution s;
    s.moveZeroes(arr);
    for (auto p = arr.begin(); p != arr.end(); p++)
    {
        cout << *p;
    }
    return 0;
}